package com.study.spring.observeModel.service;

import com.study.spring.observeModel.event.UserRegisterEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;


@Service
public class UserService implements ApplicationContextAware {


    private Logger logger = LoggerFactory.getLogger(getClass());


    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }


    public void register(String username) {

        logger.info("[register][执行用户({}) 的注册逻辑]", username);

        applicationContext.publishEvent(new UserRegisterEvent(this,username));

    }
}
